package dome1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-05-09
 * Time: 10:31
 */
public class Computer {
    public void open() {
        System.out.println("开机!");
    }
    public void close() {
        System.out.println("关机!");
    }
    public static void useDevice(IUSB iusb) {
        iusb.openDevice();
        if(iusb instanceof Mouse) { //判断传进来的iusb引用是不是Mouse类型的
            Mouse mouse = (Mouse) iusb; //向下转型(强转)  //父类引用不可以直接访问子类特有的方法
            mouse.click();
        } else if (iusb instanceof KeyBoard) {
            KeyBoard keyBoard = (KeyBoard) iusb;
            keyBoard.input();
        }
        iusb.closeDevice();
    }
}
